import { createRouter, createWebHashHistory } from 'vue-router'
import Index from './views/index.vue'
import History from './views/history.vue'
import Detail from './views/detail.vue'
import Search from './views/search.vue'

const routes = [
  {
    path: '/',
    component: Index,
    meta: {
      keepAlive: true
    }
  },
  {
    path: '/history',
    component: History,
    meta: {
      keepAlive: true,
      title: '历史会话'
    }
  },
  {
    path: '/detail',
    component: Detail,
    meta: {
      keepAlive: false,
      title: '会话详情'
    }
  },
  {
    path: '/search',
    component: Search,
    meta: {
      keepAlive: false,
      title: '搜索'
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }

  next()
})

export default router
